package ai.ann;

import java.io.IOException;

import util.essential.VariableValueGetter;

/**
 * @author S.A.M.G.
 * This class know what kind of neural network is actually selected.
 * Thus, acts depending on this knowledge.
 */
public class NeuralNetworkFactory {
	/**
	 * This is the value getter that allows to get the configuration variable values.
	 */
	private static final VariableValueGetter valueGetter = new VariableValueGetter(Property.CONFIGURATION_FILE_NAME);
	/**
	 * This constant allows to know what kind of neural network is actually selected.
	 */
	private static final byte TYPE_OF_NN = Byte.parseByte(NeuralNetworkFactory.valueGetter.getStringValue("type_of_neural_net"));
	/**
	 * This method returns a neural network instance.
	 * @param path is the path of the structural neural network file to load.
	 * @return a Neural Network.
	 * @throws IOException
	 * @throws ClassNotFoundException
	 */
	public static NeuralNetwork getInstance(String path) throws IOException, ClassNotFoundException{
		if(NeuralNetworkFactory.TYPE_OF_NN == NeuralNetwork.SINGLE){
			/**/System.out.println("Creating to use a single (X-Y-Z) neural network.");/**/
			return new SingleNeuralNetwork(path);
		}else if(NeuralNetworkFactory.TYPE_OF_NN == NeuralNetwork.COMPLEX){
			/**/System.out.println("Creating to use a complex (X-20-10-Z) neural network.");/**/
			return new ComplexNeuralNetwork(path);
		}else return null;
	}
	/**
	 * This method allows to train to a neural network, depending on what kind of those is selected.
	 * @param inputFileName is the pattern input file name.
	 * @param inputRowSelector is the pattern row selector in the input file.
	 * @param trainingRowSelector is the row selector for trainning data.
	 * @param outputFileName is the output structure file name.
	 * @param amountOfTrainningPatterns is the amount trainning patterns.
	 * @param cicles cicles is the number of cilce to trainning.
	 * @throws IOException
	 */
	public static void trainning(String inputFileName,String inputRowSelector,String trainingRowSelector,String outputFileName,int amountOfTrainningPatterns, int cicles) throws IOException{
		if(NeuralNetworkFactory.TYPE_OF_NN == NeuralNetwork.SINGLE){
			SingleNeuralNetwork.trainning(inputFileName, inputRowSelector, trainingRowSelector, outputFileName, amountOfTrainningPatterns, cicles);
		}else if(NeuralNetworkFactory.TYPE_OF_NN == NeuralNetwork.COMPLEX){
			ComplexNeuralNetwork.trainning(inputFileName, inputRowSelector, trainingRowSelector, outputFileName, amountOfTrainningPatterns, cicles);
		}
	}
}
